<?php
	// Prolongement de la session
	session_start();
	// Test si la variable de session existe, si elle contient une valeur
	if (empty($_SESSION['login'])) {
		// Redirection vers le formulaire de login
		header('Location: index.php');
		exit();
	}
?>

<?php
	// Fichier de gestion/config base de données
	require "gestion_bdd.php";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<meta name="description" content=""/> 
        <meta name="keywords" content=""> 
        <meta name="url" content=""> 
        <meta name="robots" content="all">
		<meta http-equiv="refresh" content="300">
        <title>Lunch At Home</title> 
        <link rel="icon" type="image/png" href="images/Favicon.png" /> 
		
		
        <link rel="stylesheet" type="text/css" media="all" href="Styles/bootstrap.css"/>
        <link rel="stylesheet" type="text/css" media="all" href="Styles/style.css"/>
        <!--<script src="Javascripts/jquery.min.js" type="text/javascript"></script>-->	
		
		<link rel="stylesheet" href="evenements/style.css">
		<script type="text/javascript" src="evenements/eso_tools.js"> </script>			


		<style type="text/css">
			img {
				opacity: 0.7;
				-moz-opacity: 0.7;
				-khtml-opacity: 0.7;
				filter: alpha(opacity=70);
			}
			img:hover {
				opacity: 1;
				-moz-opacity: 1;
				-khtml-opacity: 1;
			}
		</style>
		
    </head>
	
	
	<body>
		<?php
			$pageActive = 0;
			include 'headMenu.php';	
		?>
		
		<div class="well" id="corps">			
			<section>
				<div class="page-header">
					<h2 style="text-align:center">Home</h2>
				</div>	

				<img style="float:left; margin-left : 60px; margin-top : 15px; width :415px" src="Styles/images/lunch.jpg" alt="">				
				<div style="float: right; width : 330px; margin : 10px 30px 0px 0px;">					
					<div id="sidebar" style="float:left; width:326px; margin:auto;">		
						<div class="livebox_v7" style="margin:5px 16px 0px 10px; padding:0 0 0 0;">
							<div id="menu-livebox" class="tabs-item" data-tabs-type="livebox" data-tabs-active="0">
								<ul class="default" style="margin : 0">
									<li class="live" data-contentid="table-onglet1" data-classname="live"><span><span>Aujourd'hui</span></span></li>
									<li class="default-active" data-contentid="table-onglet2" data-classname="default"><span><span>Hier</span></span></li>
									<li class="last default " data-contentid="table-onglet3" data-classname="default"><span><span>Demain</span></span></li>
								</ul>
							</div>
							
							<div id="table-livebox">	
								<!-- Début onglet 1 TODAY -->
								<?php									
									$today = date("Y-m-d",time());
								
									$sql = "SELECT * FROM Offres WHERE DATE_FORMAT(Date_Fin_Reservation,'%Y-%m-%d')='".$today."' ORDER BY Date_Fin_Reservation";
									$result = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
									$num_rows = mysql_num_rows($result);

									if(isset($num_rows) && $num_rows>0) {
										echo '<div id="table-onglet1" style="display: block; ">'; // div de block !! important, a afficher dans les 2 cas
										echo '<div class="scrollbar" style="border: 0px none rgb(76, 85, 99); position: relative; overflow: hidden; width: 298px; height: 200px; ">
										<div class="scrollable-item" style="overflow: hidden; border: 0px; position: relative; margin: 0px; top: 0px; left: 0px; width: auto; height: 200px; ">';
										
										while($data = mysql_fetch_assoc($result)) {
											//echo '<div class="textcenter , date">'."test1".'</div>';										
											//echo '<div class="event-title"><span class="event">'."oooo".'</span></div>';
											$id_user = $data['ID_Utilisateurs'];
											$sql_nom = "SELECT Nom FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_nom = mysql_query($sql_nom) or die('Erreur SQL !<br>'.$sql_nom.'<br>'.mysql_error());											
											$row = mysql_fetch_row($result_nom);
											
											// Requête pour connaître le numéro de téléphone de l'utilisateur
											$sql_num = "SELECT Numero_Telephone FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_num = mysql_query($sql_num) or die('Erreur SQL !<br>'.$sql_num.'<br>'.mysql_error());											
											$row_num = mysql_fetch_row($result_num);											
											
											// Requête pour connaître l'heure de l'offre
											$sql_heure = "SELECT DATE_FORMAT(Date_Fin_Reservation,'%Hh%i') FROM Offres WHERE ID_Offres='".$data['ID_Offres']."'";
											$result_heure = mysql_query($sql_heure) or die('Erreur SQL !<br>'.$sql_heure.'<br>'.mysql_error());									
											$heure = mysql_fetch_row($result_heure);
											
											$url = base64_encode("details.php?id=".$data['ID_Offres']);
											echo '<div class="crylnk line-sets-coming" data-lnk-url="'.$url.'">'.$row[0].' - '.$row_num[0].' - '.$heure[0].'</div>';												
										}
					
										echo '</div>
											<div class="bar" style="position: absolute; padding: 0px; margin: 0px; top: 0px; right: 0px; display: none; ">
										<div class="button topButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
										<div class="scrollable" style="position: relative; overflow: hidden; line-height: 0px; font-size: 0px; ">
											<div class="knob verticalKnob" style="position: absolute; top: 0px; left: 0px; line-height: 0px; font-size: 0px; ">
												<div class="knobVerticalTip topTip" style="width: 100%; "></div>
												<div class="knobVerticalFill" style="width: 100%; "></div>
												<div class="knobVerticalTip bottomTip" style="width: 100%; "></div>
											</div>
										</div>
										<div class="button bottomButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
										</div>
										<div class="bar" style="width: 100%; position: absolute; padding: 0px; margin: 0px; left: 0px; bottom: 0px; display: none; ">
											<div class="button leftButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
											<div class="scrollable" style="position: relative; overflow: hidden; float: left; line-height: 0px; font-size: 0px; ">
												<div class="knob horizontalKnob" style="position: absolute; top: 0px; left: 0px; line-height: 0px; font-size: 0px; ">
													<div class="knobHorizontalTip leftTip" style="height: 100%; "></div>
													<div class="knobHorizontalTip rightTip" style="height: 100%; "></div>
													<div class="knobHorizontalFill" style="height: 100%; "></div>
												</div>
											</div>
											<div class="button rightButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
											<div style="height: 0px; width: 0px; clear: left; line-height: 0px; font-size: 0px; "></div>
										</div>
										<div class="corner" style="position: absolute; bottom: 0px; right: 0px; line-height: 0px; font-size: 0px; width: 16px; height: 16px; display: none; "></div>
											</div>';									
									}
									else {
										echo '<div id="table-onglet1" style="display: block; ">';  // div de block !! important, a afficher dans les 2 cas
										echo '<div class="noresult">Pas d\'évenement aujourd\'hui</div>';
									}
								?>
								</div> <!-- Fin onglet 1 -->	
								
								
								<!-- Début onglet 2 YESTERDAY -->
								<?php									
									$yesterday = date("Y-m-d",time()-84600);
								
									$sql = "SELECT * FROM Offres WHERE DATE_FORMAT(Date_Fin_Reservation,'%Y-%m-%d')='".$yesterday."' ORDER BY Date_Fin_Reservation";
									$result = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
									$num_rows = mysql_num_rows($result);

									if(isset($num_rows) && $num_rows>0) {
										echo '<div id="table-onglet2" style="display: block; ">'; // div de block !! important, a afficher dans les 2 cas
										echo '<div class="scrollbar" style="border: 0px none rgb(76, 85, 99); position: relative; overflow: hidden; width: 298px; height: 200px; ">
										<div class="scrollable-item" style="overflow: hidden; border: 0px; position: relative; margin: 0px; top: 0px; left: 0px; width: auto; height: 200px; ">';
										
										while($data = mysql_fetch_assoc($result)) {
											//echo '<div class="textcenter , date">'."test1".'</div>';										
											//echo '<div class="event-title"><span class="event">'."oooo".'</span></div>';
											$id_user = $data['ID_Utilisateurs'];
											$sql_nom = "SELECT Nom FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_nom = mysql_query($sql_nom) or die('Erreur SQL !<br>'.$sql_nom.'<br>'.mysql_error());											
											$row = mysql_fetch_row($result_nom);
											
											// Requête pour connaître le numéro de téléphone de l'utilisateur
											$sql_num = "SELECT Numero_Telephone FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_num = mysql_query($sql_num) or die('Erreur SQL !<br>'.$sql_num.'<br>'.mysql_error());											
											$row_num = mysql_fetch_row($result_num);											
											
											// Requête pour connaître l'heure de l'offre
											$sql_heure = "SELECT DATE_FORMAT(Date_Fin_Reservation,'%Hh%i') FROM Offres WHERE ID_Offres='".$data['ID_Offres']."'";
											$result_heure = mysql_query($sql_heure) or die('Erreur SQL !<br>'.$sql_heure.'<br>'.mysql_error());									
											$heure = mysql_fetch_row($result_heure);
											
											$url = base64_encode("details.php?id=".$data['ID_Offres']);
											echo '<div class="crylnk line-sets-coming" data-lnk-url="'.$url.'">'.$row[0].' - '.$row_num[0].' - '.$heure[0].'</div>';												
										}
										
										echo '</div>
											<div class="bar" style="position: absolute; padding: 0px; margin: 0px; top: 0px; right: 0px; display: block; opacity: 0; visibility: hidden; ">
												<div class="button topButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
												<div class="scrollable" style="position: relative; overflow: hidden; line-height: 0px; font-size: 0px; height: 168px; ">
													<div class="knob verticalKnob" style="position: absolute; left: 0px; line-height: 0px; font-size: 0px; height: 44px; top: 0px; ">
														<div class="knobVerticalTip topTip" style="width: 100%; "></div>
														<div class="knobVerticalFill" style="width: 100%; "></div>
														<div class="knobVerticalTip bottomTip" style="width: 100%; "></div>
													</div>
												</div>
												<div class="button bottomButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
											</div>
											<div class="bar" style="width: 100%; position: absolute; padding: 0px; margin: 0px; left: 0px; bottom: 0px; display: none; ">
												<div class="button leftButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
												<div class="scrollable" style="position: relative; overflow: hidden; float: left; line-height: 0px; font-size: 0px; ">
													<div class="knob horizontalKnob" style="position: absolute; top: 0px; left: 0px; line-height: 0px; font-size: 0px; ">
														<div class="knobHorizontalTip leftTip" style="height: 100%; "></div>
														<div class="knobHorizontalTip rightTip" style="height: 100%; "></div>
														<div class="knobHorizontalFill" style="height: 100%; "></div>
													</div>
												</div>
												<div class="button rightButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
												<div style="height: 0px; width: 0px; clear: left; line-height: 0px; font-size: 0px; "></div>
											</div>
											<div class="corner" style="position: absolute; bottom: 0px; right: 0px; line-height: 0px; font-size: 0px; width: 16px; height: 16px; display: none; "></div>
										</div>';									
									}
									else {
										echo '<div id="table-onglet2" style="display: block; ">';  // div de block !! important, a afficher dans les 2 cas
										echo '<div class="noresult">Pas d\'évenement pour la journée d\'hier</div>';
									}
								?>
								</div> <!-- Fin onglet 2 -->								
								
								<!-- Début onglet 3 TOMORROW -->
								<?php									
									$tomorrow = date("Y-m-d",time()+84600);
								
									$sql = "SELECT * FROM Offres WHERE DATE_FORMAT(Date_Fin_Reservation,'%Y-%m-%d')='".$tomorrow."' ORDER BY Date_Fin_Reservation";
									$result = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
									$num_rows = mysql_num_rows($result);

									if(isset($num_rows) && $num_rows>0) {
										echo '<div id="table-onglet3" style="display: block; ">'; // div de block !! important, a afficher dans les 2 cas
										echo '<div class="scrollbar" style="border: 0px none rgb(76, 85, 99); position: relative; overflow: hidden; width: 298px; height: 200px; ">
										<div class="scrollable-item" style="overflow: hidden; border: 0px; position: relative; margin: 0px; top: 0px; left: 0px; width: auto; height: 200px; ">';
										
										while($data = mysql_fetch_assoc($result)) {
											//echo '<div class="textcenter , date">'."test1".'</div>';										
											//echo '<div class="event-title"><span class="event">'."oooo".'</span></div>';
											$id_user = $data['ID_Utilisateurs'];
											$sql_nom = "SELECT Nom FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_nom = mysql_query($sql_nom) or die('Erreur SQL !<br>'.$sql_nom.'<br>'.mysql_error());											
											$row = mysql_fetch_row($result_nom);											
											
											// Requête pour connaître le numéro de téléphone de l'utilisateur
											$sql_num = "SELECT Numero_Telephone FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
											$result_num = mysql_query($sql_num) or die('Erreur SQL !<br>'.$sql_num.'<br>'.mysql_error());											
											$row_num = mysql_fetch_row($result_num);											
											
											// Requête pour connaître l'heure de l'offre
											$sql_heure = "SELECT DATE_FORMAT(Date_Fin_Reservation,'%Hh%i') FROM Offres WHERE ID_Offres='".$data['ID_Offres']."'";
											$result_heure = mysql_query($sql_heure) or die('Erreur SQL !<br>'.$sql_heure.'<br>'.mysql_error());									
											$heure = mysql_fetch_row($result_heure);
											
											$url = base64_encode("details.php?id=".$data['ID_Offres']);
											echo '<div class="crylnk line-sets-coming" data-lnk-url="'.$url.'">'.$row[0].' - '.$row_num[0].' - '.$heure[0].'</div>';										
										}
										echo '</div>
											<div class="bar" style="position: absolute; padding: 0px; margin: 0px; top: 0px; right: 0px; display: block; opacity: 0; visibility: hidden; ">
												<div class="button topButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
												<div class="scrollable" style="position: relative; overflow: hidden; line-height: 0px; font-size: 0px; height: 168px; ">
													<div class="knob verticalKnob" style="position: absolute; left: 0px; line-height: 0px; font-size: 0px; height: 44px; top: 0px; ">
														<div class="knobVerticalTip topTip" style="width: 100%; "></div>
														<div class="knobVerticalFill" style="width: 100%; "></div>
														<div class="knobVerticalTip bottomTip" style="width: 100%; "></div>
													</div>
												</div>
												<div class="button bottomButton" style="position: relative; line-height: 0px; font-size: 0px; "></div>
											</div>
											<div class="bar" style="width: 100%; position: absolute; padding: 0px; margin: 0px; left: 0px; bottom: 0px; display: none; ">
												<div class="button leftButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
												<div class="scrollable" style="position: relative; overflow: hidden; float: left; line-height: 0px; font-size: 0px; ">
													<div class="knob horizontalKnob" style="position: absolute; top: 0px; left: 0px; line-height: 0px; font-size: 0px; ">
														<div class="knobHorizontalTip leftTip" style="height: 100%; "></div>
														<div class="knobHorizontalTip rightTip" style="height: 100%; "></div>
														<div class="knobHorizontalFill" style="height: 100%; "></div>
													</div>
												</div>
												<div class="button rightButton" style="position: relative; float: left; line-height: 0px; font-size: 0px; "></div>
												<div style="height: 0px; width: 0px; clear: left; line-height: 0px; font-size: 0px; "></div>
											</div>
											<div class="corner" style="position: absolute; bottom: 0px; right: 0px; line-height: 0px; font-size: 0px; width: 16px; height: 16px; display: none; "></div>
										</div>';									
									}
									else {
										echo '<div id="table-onglet3" style="display: block; ">';  // div de block !! important, a afficher dans les 2 cas
										echo '<div class="noresult">Pas d\'évenement pour la journée de demain</div>';
									}
								?>
								</div> <!-- Fin onglet 3 -->
							</div>
							<div id="footer-livebox">
								<a class="red sprite" onclick="window.open(this.href, &#39;_blank&#39;); return false;" href="offres.php">Tous les évenements</a>
							</div>
						</div>
						<script type="text/javascript">					
							if(typeof Eurosport_v7 != 'undefined') {
								if(Eurosport_v7.Initialize) {												
									Eurosport_v7.Initialize();
								}
							}					
						</script>
					</div> <!-- End sidebar -->       
				</div>  <!-- End div pour les evenement --> 
				
				
				<div style="margin-top:290px; margin-left:60px; ">
					<h3 style="margin-bottom: 10px;">Lunch At Home</h3>
					
					<script src="JQuery/jquery-1.8.3.js" type="text/javascript"></script>
					<script src="JQuery/jquery-ui.1.8.js" type="text/javascript"></script>
					<script src="Javascripts/Graphe.js" type="text/javascript"></script>
					<script src="Javascripts/highcharts.js" type="text/javascript"></script>
					<div id="container" style="min-width: 260px; height: 400px; margin: 0 auto; margin-top:40px;"></div>
					<div id="container2" style="min-width: 260px; height: 400px; margin: 0 auto; margin-top:40px;"></div>
					<div id="container3" style="min-width: 260px; height: 400px; margin: 0 auto; margin-top:40px;"></div>
					
				</div>				
				<p style="margin-top: 40px; margin-bottom : -10px; text-align : right; font-size: 12px"> &#169 Copyright 2013 Lunch At Home</p>				
			</section>                
		</div>
	</body>
</html>